<!doctype html>



  


<html class="theme-next pisces use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/vendors/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/vendors/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="王雨峰, 博客" />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.0.1" />






<meta name="description" content="工大野生助手https://github.com/wangyufeng0615/bjuthelper
访问量
预览
功能
查某学期的各科成绩。
查所有学期总的加权平均分和平均GPA。

运行模式
这两个PHP页面运行在Apache中；
Apache安装在我的电脑上；
电脑连了学校的内网，也就是bjut-wifi或者插网线；
将自己电脑的80端口映射到外网。映射的方法很多，我用的是ngrok这个开源">
<meta property="og:type" content="article">
<meta property="og:title" content="工大野生助手">
<meta property="og:url" content="http://wangyufeng.org/2016/07/24/工大野生助手/index.html">
<meta property="og:site_name" content="王雨峰的博客">
<meta property="og:description" content="工大野生助手https://github.com/wangyufeng0615/bjuthelper
访问量
预览
功能
查某学期的各科成绩。
查所有学期总的加权平均分和平均GPA。

运行模式
这两个PHP页面运行在Apache中；
Apache安装在我的电脑上；
电脑连了学校的内网，也就是bjut-wifi或者插网线；
将自己电脑的80端口映射到外网。映射的方法很多，我用的是ngrok这个开源">
<meta property="og:image" content="http://7xku3h.com1.z0.glb.clouddn.com/16-7-16/85684382.jpg">
<meta property="og:image" content="http://7xku3h.com1.z0.glb.clouddn.com/16-7-23/12366574.jpg">
<meta property="og:image" content="http://7xku3h.com1.z0.glb.clouddn.com/16-7-23/47965690.jpg">
<meta property="og:updated_time" content="2016-09-03T03:59:18.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="工大野生助手">
<meta name="twitter:description" content="工大野生助手https://github.com/wangyufeng0615/bjuthelper
访问量
预览
功能
查某学期的各科成绩。
查所有学期总的加权平均分和平均GPA。

运行模式
这两个PHP页面运行在Apache中；
Apache安装在我的电脑上；
电脑连了学校的内网，也就是bjut-wifi或者插网线；
将自己电脑的80端口映射到外网。映射的方法很多，我用的是ngrok这个开源">
<meta name="twitter:image" content="http://7xku3h.com1.z0.glb.clouddn.com/16-7-16/85684382.jpg">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Pisces',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: 0,
      author: '博主'
    }
  };
</script>




  <link rel="canonical" href="http://wangyufeng.org/2016/07/24/工大野生助手/"/>

  <title> 工大野生助手 | 王雨峰的博客 </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  










  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">王雨峰的博客</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">随便写点东西，为互联网贡献一些比特~</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                工大野生助手
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2016-07-24T12:48:29+08:00" content="2016-07-24">
              2016-07-24
            </time>
          </span>

          

          
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="工大野生助手"><a href="#工大野生助手" class="headerlink" title="工大野生助手"></a>工大野生助手</h1><p><a href="https://github.com/wangyufeng0615/bjuthelper" target="_blank" rel="external">https://github.com/wangyufeng0615/bjuthelper</a></p>
<h2 id="访问量"><a href="#访问量" class="headerlink" title="访问量"></a>访问量</h2><p><img src="http://7xku3h.com1.z0.glb.clouddn.com/16-7-16/85684382.jpg" alt=""></p>
<h2 id="预览"><a href="#预览" class="headerlink" title="预览"></a>预览</h2><p><img src="http://7xku3h.com1.z0.glb.clouddn.com/16-7-23/12366574.jpg" alt=""><br><img src="http://7xku3h.com1.z0.glb.clouddn.com/16-7-23/47965690.jpg" alt=""></p>
<h2 id="功能"><a href="#功能" class="headerlink" title="功能"></a>功能</h2><ul>
<li>查某学期的各科成绩。</li>
<li>查所有学期总的加权平均分和平均GPA。</li>
</ul>
<h2 id="运行模式"><a href="#运行模式" class="headerlink" title="运行模式"></a>运行模式</h2><ul>
<li>这两个PHP页面运行在Apache中；</li>
<li>Apache安装在我的电脑上；</li>
<li>电脑连了学校的内网，也就是bjut-wifi或者插网线；</li>
<li>将自己电脑的80端口映射到外网。映射的方法很多，我用的是ngrok这个开源工具，也可以用花生壳等。</li>
<li>【手机端(扫二维码访问登陆页面)】&lt;—&gt;【外网映射服务器】&lt;–(学校网关)–&gt;【内网电脑,运行着Apache】&lt;—&gt;【教务网站】</li>
</ul>
<h2 id="细节"><a href="#细节" class="headerlink" title="细节"></a>细节</h2><ul>
<li><code>login_grade.php</code>负责登陆，<code>require_grade.php</code>负责具体的查询。</li>
</ul>
<h3 id="login-grade-php"><a href="#login-grade-php" class="headerlink" title="login_grade.php"></a>login_grade.php</h3><ul>
<li>UI用的是「WeUI」，微信团队做的，和微信的视觉效果一致；</li>
<li>每个学校的正方教务都不太一样，我的代码中的各种http header参数、post参数基本符合北工大的教务网站。</li>
<li>教务系统的默认登陆页面是<code>default2</code>，可以换换default后面的数字，可以有不需要验证码的登陆页面。</li>
</ul>
<h3 id="require-grade-php"><a href="#require-grade-php" class="headerlink" title="require_grade.php"></a>require_grade.php</h3><ul>
<li>中文编码容易出现乱码，涉及到本地IDE的编码、PHP的编码和网站的编码；</li>
<li>有两种post，第一种是登陆，第二种是获取成绩信息。获取成绩信息的时候有多次post，分别是获取某学期的成绩和获取总成绩；</li>
<li>构造POST的思路：打开浏览器开发者工具，先正常走一遍查询成绩的流程，观察POST数据的key和value，并在代码中构造；</li>
<li>由于页面返回的是一坨DIV，而且既没有name属性也没有id属性，所以需要将table标签整个转成array，并观察所需要的信息的位置，通过数组下标的方式访问；</li>
<li>总的平均GPA无法区分主修专业和二专业/辅修专业，因为查询所有科目的总成绩页面中没有任何标签能区分这两者。</li>
</ul>
<h2 id="其他"><a href="#其他" class="headerlink" title="其他"></a>其他</h2><ul>
<li>其实就是个爬虫，模拟了登陆正方教务系统并查询成绩的过程。Python写爬虫的话可能更方便，Python有个库requests，非常好用。</li>
<li>PHP中嵌入HTML感觉很不优雅，但HTML中嵌入PHP也好不到哪里去，有什么更好的办法吗？</li>
<li>网上有很多关于正方教务的东西，虽然不太容易直接照搬，但学习价值很大。table转html的函数我就是从网上找的。</li>
<li>交流请联系 807103724@qq.com，微信同QQ。</li>
<li>欢迎提交Issue和Pull Request！</li>
</ul>
<h2 id="LICENSE-假装我写出了一个开源的东西"><a href="#LICENSE-假装我写出了一个开源的东西" class="headerlink" title="LICENSE(假装我写出了一个开源的东西)"></a>LICENSE(假装我写出了一个开源的东西)</h2><p>MIT</p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2016/07/14/mhn-install/" rel="next" title="安装大型Linux软件时一些关于下载的坑">
                <i class="fa fa-chevron-left"></i> 安装大型Linux软件时一些关于下载的坑
              </a>
            
          </div>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2016/08/31/internship-summary/" rel="prev" title="在创宇实习两个月的收获和感悟">
                在创宇实习两个月的收获和感悟 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/avatar.gif"
               alt="Alan" />
          <p class="site-author-name" itemprop="name">Alan</p>
          <p class="site-description motion-element" itemprop="description">Alan Wang's personal blog.</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">57</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              
                <span class="site-state-item-count">9</span>
                <span class="site-state-item-name">分类</span>
              
            </div>
          

          
            <div class="site-state-item site-state-tags">
              
                <span class="site-state-item-count">4</span>
                <span class="site-state-item-name">标签</span>
              
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        

      </section>

      
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">
            
              
            
            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#工大野生助手"><span class="nav-number">1.</span> <span class="nav-text">工大野生助手</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#访问量"><span class="nav-number">1.1.</span> <span class="nav-text">访问量</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#预览"><span class="nav-number">1.2.</span> <span class="nav-text">预览</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#功能"><span class="nav-number">1.3.</span> <span class="nav-text">功能</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#运行模式"><span class="nav-number">1.4.</span> <span class="nav-text">运行模式</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#细节"><span class="nav-number">1.5.</span> <span class="nav-text">细节</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#login-grade-php"><span class="nav-number">1.5.1.</span> <span class="nav-text">login_grade.php</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#require-grade-php"><span class="nav-number">1.5.2.</span> <span class="nav-text">require_grade.php</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#其他"><span class="nav-number">1.6.</span> <span class="nav-text">其他</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#LICENSE-假装我写出了一个开源的东西"><span class="nav-number">1.7.</span> <span class="nav-text">LICENSE(假装我写出了一个开源的东西)</span></a></li></ol></li></ol></div>
            
          </div>
        </section>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2016</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Alan</span>
</div>

<div class="powered-by">
  Powered by <a class="theme-link" href="https://hexo.io">Hexo</a> 
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Pisces
  </a>
</div>

        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/vendors/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/vendors/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/vendors/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.1"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.0.1"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.0.1"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.0.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.0.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.1"></script>



  



  




  
  

  

  

  

</body>
</html>
